public class ClassTest {
    public static void main(String[] args) throws ClassNotFoundException {
        Person personOne = new Student();
        System.out.println("这个人是：" + personOne.name);

        //通过对象获得class
        Class c1 = personOne.getClass();
        System.out.println(c1);
        System.out.println(c1.hashCode());
        //通过forname获得
        Class c2 = Class.forName("Student");//注意该括号中填写的格式是
                                                    //：包名.类名，如果在默认包里（没有package）
                                                    //就只写类名就行
        System.out.println(c2);
        System.out.println(c2.hashCode());
        //通过类名.class获得
        Class c3 = Student.class;
        System.out.println(c3);
        System.out.println(c3.hashCode());
        //-----------------------------
        //包装类中都有TYPE的属性，可以获取到
        Class c4 = Integer.TYPE;
        System.out.println(c4);
        //获得父类的类型
        Class c5 = c1.getSuperclass();
        System.out.println(c5);
    }
}
class Person{
    public String name;
     int age;

    public Person() {

    }
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public String toString() {
        return "person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class Student extends Person{
    public Student() {
        this.name = "学生";
        this.age = 18;
    }
}

class Teather extends Person{
    public Teather(String name, int age) {
        super(name, age);
    }

    public Teather() {
    }
}